package com.qianfeng.wuyang.himalaya.adapter.broadcastadapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qianfeng.wuyang.himalaya.R;
import com.qianfeng.wuyang.himalaya.activity.RadiochartsActivity;
import com.qianfeng.wuyang.himalaya.bean.broadcastbean.BC_topRadiosEntity;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created by wuyang on 2016/12/5.
 */

public class BCRankingRecyclerAdapter extends RecyclerView.Adapter<BCRankingRecyclerAdapter.ViewHolder> {
    private Context context;
    private List<BC_topRadiosEntity> list;

    public BCRankingRecyclerAdapter(Context context) {
        this.context = context;
        list = new ArrayList<>();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        ViewHolder viewHolder = new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_localrecycler_bc, parent, false));

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        //绑定数据
        BC_topRadiosEntity items = list.get(position);


        //加载图片
        Picasso.with(context).load(items.getCoverLarge()).into(holder.image_localrecycler);

        holder.title_localrecycler.setText(items.getName());
        holder.playingTV_localrecycler.setText(items.getProgramName());
        int count = items.getPlayCount()/10000;
        holder.peopleTV_localrecycler.setText(count+"万人");



}
    @Override
    public int getItemCount() {
        return list.size();
    }

    //添加数据的方法
    public void addAll(Collection<? extends BC_topRadiosEntity> collection){

        int size = list.size();
        list.addAll(collection);
        notifyItemRangeInserted(size,collection.size());
    }



    public static class ViewHolder extends RecyclerView.ViewHolder{

        private ImageView image_localrecycler;//展示图片
        private TextView title_localrecycler;
        private TextView playingTV_localrecycler;
        private TextView peopleTV_localrecycler;
        private ImageView playRadio;//播放的按钮


        public ViewHolder(View itemView) {
            super(itemView);
            image_localrecycler = ((ImageView) itemView.findViewById(R.id.image_localrecycler));
            title_localrecycler = ((TextView) itemView.findViewById(R.id.title_localrecycler));
            playingTV_localrecycler = ((TextView) itemView.findViewById(R.id.playingTV_localrecycler));
            peopleTV_localrecycler = ((TextView) itemView.findViewById(R.id.peopleTV_localrecycler));
            playRadio = ((ImageView) itemView.findViewById(R.id.playRadio));

        }
    }
}
